/**
 * Copyright (c) 快宝网络 kuaidihelp.com Co., Ltd. All Rights Reserved 禁止外泄以及用于其它的商业用途
 */

import request from '@/utils/request';
import { formatTableRequest, operateError, operateSuccess } from '../_utils';

interface ListReq {
  search?: string;
  status?: string;
  page_size?: number;
}
// 获取
export async function getVipPrinter(params: any): Promise<any> {
  const { print_code: search, status, ...restParams } = params;
  const req: ListReq = { search };
  if (status !== 'all') {
    req.status = status;
  }
  return formatTableRequest<ListReq>(
    '/sendVip/sendVipList',
    {
      ...req,
      ...restParams,
    },
    ({ page_size: size, ...restReq }) => ({
      ...restReq,
      size,
    }),
  );
}

// 添加
export async function addVipPrinter(params: any): Promise<any> {
  const { print_code, ...restParams } = params;
  return request('/sendVip/sendVipAdd', {
    method: 'POST',
    data: {
      ...restParams,
      print_code: print_code.split(/[,，]+|\s+/).filter((item: string) => !!item),
    },
  })
    .then(operateError)
    .then(operateSuccess);
}

// 撤销
export async function revokeVipPrinter(params: any): Promise<any> {
  return request('/sendVip/cancelVip', {
    method: 'POST',
    data: params,
  })
    .then(operateError)
    .then(operateSuccess);
}

// 删除
export async function deleteVipPrinter(params: any): Promise<any> {
  return request('/sendVip/sendVipDel', {
    method: 'POST',
    data: params,
  })
    .then(operateError)
    .then(operateSuccess);
}
